package cn.wolfcode.demo1.service.impl;



import cn.wolfcode.demo1.domain.Department;
import cn.wolfcode.demo1.mapper.DepartmentMapper;
import cn.wolfcode.demo1.qo.QueryObject;
import cn.wolfcode.demo1.service.DepartmentService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

@Service
public class DepartmentServiceImpl implements DepartmentService {
    @Autowired
    private DepartmentMapper departmentMapper;
    @Override
    @Transactional
    public void add(Department department) {
        departmentMapper.add(department);
    }

    @Override
    @Transactional
    public void delById(Long id) {
            departmentMapper.delete(id);
    }

    @Override
    @Transactional
    public void edit(Department department) {
        departmentMapper.edit(department);
    }

    @Override
    public Department selOneById(Long id) {
        return departmentMapper.selOneById(id);
    }

    @Override
    public List<Department> selAll() {
        return departmentMapper.selAll();
    }

    @Override
    public PageInfo<Department> query(QueryObject qo) {
//        int totalCount = departmentMapper.selectForCount(qo);
//        if (totalCount == 0){
//            return new PageResult<>();
//        }
//        List<Department> departments = departmentMapper.selectForList(qo);

//        return new PageResult<>(qo.getCurrentPage(),qo.getPageSize(),totalCount,departments);
        PageHelper.startPage(qo.getCurrentPage(),qo.getPageSize());
        return new PageInfo<Department>(departmentMapper.selectForList(qo));
    }
}
